package com.gg.user.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gg.dao.UserMapper;
import com.gg.entity.User;
@Service
public class UserService {
	@Autowired
	private  UserMapper userMapper;
	public  Map<Boolean,String> regist(User user){
		User u=null;
		Map<Boolean,String> map=new HashMap<Boolean, String>();
		u=userMapper.selectUserByEmail(user);
		if(u!=null) {
			map.put(false, "邮箱已经注册");
				return map;
			
		}
		u=userMapper.selectUserByTel(user);
		if(u!=null) {
			map.put(false, "手机已经注册");
			return map;
		}
		userMapper.insertUser(user);
		map.put(true, "注册成功！");
		return map;
	}
	
	public  List<User> getAllUsers(){
		return userMapper.selectAllUsers();
		
	}
	public User login(User user) {
		User u=null;
		if(user.getEmail()!=null) {
			u=userMapper.selectUserByEmailAndPassword(user);
			
			
		}else {
			
			u=userMapper.selectUserByTelAndPassword(user);
		}
		return u;
	}
	
}
